<?php 
/* this script generates an xml sitemap for search engines */
require_once("config.php");

// application internal classes
require_once("class/cache.class.php");
require_once("class/database.class.php");
require_once("class/blog.class.php");
require_once("class/facebook.class.php");
require_once("class/search.class.php");
require_once("class/amazon.class.php");
require_once("class/analytics.class.php");

// output the correct header content-type
header("Content-Type: text/xml;");

// output the xml document head
echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
	."<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");

// define the server-url to use for loc entries
$host = $_SERVER["SERVER_NAME"];
	
// instanciate the blog and thereby the db
$b = new blog($_SERVER["HTTP_HOST"]);

// get all articles from the database
$articleList = $b->getLatestArticles(99999);

// ouput the sitemap for the article
for($a=0;$a<count($articleList);$a++){
	echo ("<url><loc>http://".$host."/".$articleList[$a]["url"].".html</loc>"
		."<lastmod>".date("Y-m-d",time()-86000)."</lastmod>"
		."<changefreq>daily</changefreq>"
		."<priority>1.0</priority>"
		."</url>");
}

$categoryList = $b->db->getCategoryPublishedList();
for($c=0;$c<count($categoryList);$c++){
	echo ("<url><loc>http://".$host."/k/".$categoryList[$c]["url"]."</loc>"
		."<lastmod>".date("Y-m-d",time()-86000)."</lastmod>"
		."<changefreq>daily</changefreq>"
		."<priority>0.5</priority>"
		."</url>");	
}

// finally close the xml file
echo ("</urlset>");
?>